package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @Author LEO
 * @Date 2021年12月16日 19:39
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 登录
     * @param userInfo
     * @return
     */
    @Override
    public UserInfo login(UserInfo userInfo) {
        //sql: select * from user_info where login_name = ? and passwd=?
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("login_name",userInfo.getLoginName());
        // 对用户输入的密码进行加密操作 MD5
        String newPassword = DigestUtils.md5DigestAsHex(userInfo.getPasswd().getBytes());
        queryWrapper.eq("passwd",newPassword);
        UserInfo info = userInfoMapper.selectOne(queryWrapper);
        if (info !=null){
            return info;
        }
        return null;
    }
}
